<script type="text/javascript">
	function toggleLayer( whichLayer, show ) {
		var elem, vis;
		if(document.getElementById ) // this is the way the standards work
			elem = document.getElementById( whichLayer );
		else if( document.all ) // this is the way old msie versions work
			elem = document.all[whichLayer];
		else if( document.layers ) // this is the way nn4 works
			elem = document.layers[whichLayer];
		vis = elem.style;
		if (show) {
			vis.display = 'block';
		} else {
			vis.display = 'none';
		}
	}
</script>
<?php echo $link->projectLink($project_id, $project_name, __('documents_by_date', true), '/documents/'); ?> - 
<?php echo $html->link(__('add_document', true), "javascript:toggleLayer('adddocument', true)"); ?><br />
<div id="adddocument" style="display:none;" class="largebloc2">
<?php echo $form->create('Document', array('action' => 'add', 'type'=>'file')); ?>
<table width="100%" border="0" cellspacing="2" cellpadding="0">
  <tr>
    <td width="90"><?php echo $form->label(__('file', true)); ?></td>
    <td><?php echo $form->file('File'); ?></td>
  </tr>
  <tr>
    <td width="90"><?php echo $form->label(__('name', true)); ?></td>
    <td><?php echo $form->text('Document.name'); ?></td>
  </tr>
  <tr>
    <td width="90"><?php echo $form->label('Description'); ?></td>
    <td><?php echo $form->textArea('Document.description'); ?>	
		<?php echo $form->hidden('Document.project_id', array ('value' => $project_id)); ?>
        <?php echo $form->hidden('project_name', array ('value' => $project_name)); ?>
		<?php echo $form->hidden('Document.ticket_id', array ('value' => 0)); ?>
    </td>
  </tr>
  <tr>
	<td width="90"><?php echo $form->label(__('fast_access', true)); ?></td>
	<td><?php echo $form->radio('Document.access', array('1'=>'yes', '2'=>'no'), Null, array()); ?></td>
  </tr>
  <tr>
    <td width="90"><?php echo $form->submit(__('upload', true)); ?></td>
    <td>&nbsp;<?php echo $html->link(__('cancel', true), ''); ?></td>
  </tr>
</table>
<?php echo $form->end(); ?>
</div>
<br />
<h2><?php echo __('documents_by_letter', true); ?></h2>
<div class="largebloc2">
<?php 

$pred_document_letter = ' ';
$i = 0;
foreach($object as $doc) {
	if (ucfirst($doc['Document']['name'][0]) != $pred_document_letter) {
		if ($i > 0)
			echo '</tbody></table>';
		$i = 0;
		echo '<h3>'.ucfirst($doc['Document']['name'][0]).'</h3>';
		echo '<table width="100%"><tbody>';
	}
	$pred_document_letter = ucfirst($doc['Document']['name'][0]);
	if ($i % 2)
		echo '<tr class="even">';
	else
		echo '<tr class="odd">';
	$i++;
	echo '<td width="54">'.$html->image('/document_ext/'.$doc['Document']['extention'].'.png', array('alt'=>"", 'border'=>"0")).'</td>';
	echo '<td><a href="#"><strong>'.$doc['Document']['name'].'</strong></a><br \>';
	if ($doc['Document']['description'] != '')
		echo $doc['Document']['description'].'<br \>';
	echo '<span class="details block">'.__('last_updated', true).$doc['User']['firstname'].' '.$doc['User']['lastname'].' - '.date('l, j F Y', strtotime($doc['Document']['update_date']));
	echo ' | '.$number->toReadableSize($doc['Document']['size']);
	echo ($allowDelete || $doc['User']['id'] == $user_id) ? ' ['. $html->link(__('edit', true), '/'.$doc['Project']['rewrite_name'].'/'.$doc['Project']['id'].'/documents/edit/'.$doc['Document']['id'].'/').' | '.$html->link(__('delete', true), '/'.$doc['Project']['rewrite_name'].'/'.$doc['Project']['id'].'/documents/del/'.$doc['Document']['id'].'/', NULL, __('are_you_sure', true)).']' : ' ';
	echo '</span></td></tr>';
}
if ($i > 0)
	echo '</tbody></table>';
else
	echo 'Aucun document n\'est disponible';
?>
</div>